<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>TchModify_Page</title>
<script>var userid = sessionStorage.getItem('testKey');
if(userid == null || userid == "")
	{
	window.location = "/login.html";
	}
</script>
<style>
body
{
font-size:75%;
font-family:verdana,arial,'sans serif';
background-repeat:repeat-x;
background-color:#FFFFF0;
color:#000080;
}

h1 {font-size:200%;}
h2 {font-size:140%;}
h3 {font-size:110%;}

th {background-color:#ADD8E6;}
ol {list-style:upper-roman;}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
}

li {
    float: left;
}

li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover {
    background-color: #111;
}
.active{

background-color: #bfbfbf;
}
</style>
<script src="../jquery-3.5.1.js"></script>
<script src="../jquery.cookie.js"></script>
<script type="text/javascript">
 window.onload = function(){
	 
    $.ajax({
 
        type: 'GET',
        url: "/teachers",
        contentType: "application/json;cherset=utf-8",
        dataType: "json",
        success: function (data){
        	 	var InData=data;
                var html = "";
                for(var i=0;i<data.length;i++){
           		 //访问每一个的属性，根据属性拿到值
           	       
  					html +="<tr>";
  					html +=		"<td>" + data[i].tid +"</td>";
  					html +=		"<td>" + data[i].name +"</td>";
  					html +=		"<td><a href='ChangeTch.html?tid="+ data[i].tid +"'>修改</a></td>";
  					console.log(data[i].tid);
 
  					html += 	"<td><button type='button' onclick='deleteTch("+ data[i].tid + ")'>删除 </button></td>";
  					html +="</tr>";
           	    }
                
                $("#inTable").html(html);
                
                    
              } ,
        error: function (data) {
            alert("error:" + JSON.stringify(data));}
    });
}

 function deleteTch(tid){
	 if(confirm("真的要删除？")){
		 $.ajax({
			 
		        type: 'Delete',
		        url: "/teachers/"+ tid,
		        contentType: "application/json;cherset=utf-8",
		        success: function (){
		        	alert("删除成功!");
		        	 location.reload();
		        },
		        error: function () {
		            alert("error")}
		     })
	}
	 
 }
</script>



</head>
<body>
<ul><!--导航栏 -->
  <li><a href="AdminPage.html">主页</a></li>
  <li><a class="active" href="TchModify.html">老师修改页面</a></li>
  <li><a href="StuModify.html">学生修改页面</a></li>
  <li><a href="CoursesModify.html">课程修改页面</a></li>
  <li><a href="CourseTchModify.html">教师开课修改页面</a></li>
  <li><a href="AllScore.html">分数查询页面</a></li>
</ul>
<br/>
<a href="AddTch.html"><button type="button">增加教师</button></a>
<em id="em1"></em>
<table >
             <thead>
                <tr>
                    <th>教师编号</th>
                    <th>名字</th>
                    <th></th>
                    <th></th>
         
                 </tr>
              </thead>
 
              <tbody  id="inTable">
              
              </tbody>
</table>
  
</body>
</html>